// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/equipment/api/DashboardBusinessApi'

import ComClass from '@api/ComQuery'
import ListClass from '@api/equipment/model/DashboardBusinessQueryReq'

const InfoClass = ListClass

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  async getList(param, TIP = '查询列表') {
    const DTO = CORE.grpcDTO(ListClass, param, COM)
    const resp = await CORE.grpc(TIP, CLIENT, 'queryEquipmentOldDeptList', DTO)
    return [resp.comQuery.totalCount, resp.content || []]
  },

  // —————————————————————————————— 信息 —————————————————————————————— //

  transInfoParam(infoParam, { state: { param } }) {
    return param
  },
  async getInfo(param, TIP = '查询信息') {
    const DTO = CORE.grpcDTO(InfoClass, param, COM)
    const resp = await CORE.grpc(TIP, CLIENT, 'queryEquipmentOldByTypeChart', DTO)
    return resp
  },
  transInfo(obj) {
    return {
      all: transBar(obj),
    }
  },
}

// ============================== 内部方法 ============================== //

const transBar = ({ line = [], content = {} }) => {
  if (CORE.isEmpty(line) || CORE.isEmpty(content.data)) {
    return { xData: [''], arrayList: [[0]] }
  }
  return {
    xData: line,
    arrayList: [content.data],
  }
}
